#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)
#define to first
#define w second

using namespace std;

class Graph
{
    struct Edge
    {
        int vs,vt,w;
        Edge* next;
        void set(int a,int b,int c,Edge* nt = NULL)
        {
            vs=a,vt=b,w=c,next=nt;
        }
    };
#define EACH(i,vs) for(Edge* i=head[vs];i;i=i->next)
  public:
  int vn,arcn;
  Edge *edge,**head;
  Graph(int n,int m)
  {
    vn=n+1,arcn=0;
    edge = new Edge[m+10];
    head = new Edge*[n+10];
    fill(head,head+n+10,(Edge*)NULL);
  }
  ~Graph()
  {
    delete(edge);
    delete(head);
  }
  void AddArc(int vs,int vt,int w)
  {
    edge[arcn].set(vs,vt,w,head[vs]);
    head[vs]=&edge[arcn++];
  }
  int GetAns(int tmax)
  {
    vector<int> dist(tmax+1,0);
    vector<bool> inQueue(tmax+1,false);
    queue<int> q;
    REP(i,tmax) q.push(tmax-1-i);
    while(!q.empty())
    {
        int vs = q.front();q.pop();
        inQueue[vs]=false;
        EACH(ep,vs) if(dist[vs]+ep->w>dist[ep->vt])
        {
            dist[ep->vt]=dist[vs]+ep->w;
            if(!inQueue[ep->vt])
            {
                q.push(ep->vt);
                inQueue[ep->vt]=true;
            }
        }
    }
    return dist[tmax];
  }
};

int n;

int main()
{
    while(cin>>n)
    {
        int ans = 0;
        int tmax = -1;
        Graph g(50000,n+50000*2);
        REP(i,n)
        {
            int vs,vt,w;
            scanf("%d%d%d",&vs,&vt,&w);
            g.AddArc(vs,vt+1,w);
            tmax = max(tmax,vt+1);
        }
        REP(i,tmax) g.AddArc(i,i+1,0);
        REP(i,tmax) g.AddArc(i+1,i,-1);
        printf("%d\n",g.GetAns(tmax));
    }
    return 0;
}

